package com.emperor.controller.vmservice;

import com.emperor.dto.RegionAddDto;
import com.emperor.result.Result;
import com.emperor.service.RegionService;
import com.emperor.vo.SkuClassPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/vm-service/region")
@Api(tags = "区域管理")
public class RegionController {
    @Autowired
    private RegionService regionService;

    /**
     * 区域搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param className
     * @return
     */
    @ApiOperation("区域搜索")
    @GetMapping("/search")
    public SkuClassPageVo findAll(Integer pageIndex, Integer pageSize, String className) {
        SkuClassPageVo vo = regionService.findAll(pageIndex, pageSize, className);
        return vo;
    }

    /**
     * 新增区域
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增区域")
    @PostMapping
    public Result add(@RequestBody RegionAddDto dto) {
        regionService.add(dto);
        return Result.success();
    }

    /**
     * 根据regionId修改区域
     * @param regionId
     * @param dto
     * @return
     */
    @ApiOperation("根据regionId修改区域")
    @PutMapping("/{regionId}")
    public Result updateId(@PathVariable Integer regionId, @RequestBody RegionAddDto dto) {
        regionService.updateId(regionId, dto);
        return Result.success();
    }

    /**
     * 根据regionId删除区域
     *
     * @param regionId
     * @return
     */
    @ApiOperation("根据regionId删除区域")
    @DeleteMapping("/{regionId}")
    public Result deleteById(@PathVariable Integer regionId) {
        regionService.deleteById(regionId);
        return Result.success();
    }
}
